﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.DataContract;
using WordNet.Core.ElementContracts;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestSenseLine: UnitTestBase
    {
        const string SENSET_LINE = @"dog%1:05:00:: 02064081 1 42";
       
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }

        [TestMethod]
        public void CanParseSenseLine()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
        }

        [TestMethod]
        public void CanParseSenseKey()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
            Assert.AreEqual("dog", sense.SenseKey.Lemma);
            Assert.AreEqual(0, sense.SenseKey.LexicalID);
            Assert.AreEqual(5, sense.SenseKey.LexicalFile.Number);
            Assert.AreEqual(POS.GetPartOfSpeech((DbPartOfSpeechType) 1), sense.SenseKey.LexicalFile.PartOfSpeech);
        }

        [TestMethod]
        public void CanParseSenseOffset()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
            Assert.AreEqual(int.Parse("02064081"), sense.Offset);
        }

        [TestMethod]
        public void CanParseSenseNumber()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
            Assert.AreEqual(1, sense.SenseNumber);
        }

        [TestMethod]
        public void CanParseSensePOS()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
            Assert.AreEqual(POS.NOUN, sense.PartOfSpeech);
        }

        [TestMethod]
        public void CanParseSenseTagCount()
        {
            var parser = Container.GetExportedValue<IParser<ISenseEntry>>();
            ISenseEntry sense = parser.Parse(SENSET_LINE);
            Assert.IsNotNull(sense);
            Assert.AreEqual(42, sense.TagCount);
        }
    }
}
